home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 24 / AACD 24.iso / AACD / Programming / imageio.lib / dev / examples / getinfo / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-08-09  |  3.2 KB  |  132 lines

  1. /* This example use of imageio.library loads the image file specified
  2.         on the command line and views its attributes
  3. */
  4.  
  5. #include <stdio.h>
  6.  
  7. #include <dos/dos.h>
  8. #include <exec/memory.h>
  9. #include <exec/types.h>
  10.  
  11. #include <clib/dos_protos.h>
  12. #include <clib/exec_protos.h>
  13. #include <clib/intuition_protos.h>
  14.  
  15. #include <pragmas/dos_pragmas.h>
  16. #include <pragmas/exec_pragmas.h>
  17. #include <pragmas/intuition_pragmas.h>
  18.  
  19. #include <imageio/imageio.h>
  20. #include <imageio/imageio_protos.h>
  21. #include <imageio/imageio_pragmas.h>
  22.  
  23. /* Function prototypes */
  24. __saveds __asm ULONG progressFunc( register __d0 ULONG curr, register __d1 ULONG lines, register __a0 void *userdata );
  25.  
  26. extern struct Library *DOSBase;
  27. struct Library *ImageIOBase, *IntuitionBase;
  28.  
  29. void main( int argc, char **argv )
  30. {
  31.     if ( argv[1] != NULL )
  32.     {
  33.         ImageIOBase = OpenLibrary( "imageio.library", 2 );
  34.         IntuitionBase = OpenLibrary( "intuition.library", NULL );
  35.         if ( IntuitionBase && ImageIOBase )
  36.         {
  37.             struct ImageHandle *ih;
  38.             ULONG err;
  39.             BPTR fp;
  40.  
  41.             fp = Open( argv[1], MODE_OLDFILE );
  42.             if ( fp != NULL )
  43.             {
  44.                 err = AllocImage( &ih,
  45.                     IMG_SrcFile, fp,
  46.                     TAG_DONE );
  47.                 if ( !err )
  48.                 {
  49.                     ULONG num = 1, denom = 1;
  50.                     ULONG x, y, bpp, rs, attrs[8];
  51.                     UBYTE cs, it, depth;
  52.                     BOOL encoded;
  53.  
  54.                     err = GetImageAttrs( ih,
  55.                         IMG_ImageType, &it,
  56.                         TAG_DONE );
  57.                     if ( !err )
  58.                     {
  59.                         printf("Image type=%d\n",it);
  60.                     }
  61.  
  62.                     err = GetImageAttrs( ih,
  63.                         IMG_Width, &x,
  64.                         IMG_Height,&y,
  65.                         IMG_BytesPerPixel, &bpp,
  66.                         IMG_ColourSpace, &cs,
  67.                         IMG_RowSize, &rs,
  68.                         IMG_TestScaleNum, num,
  69.                         IMG_TestScaleDenom, denom,
  70.                         IMG_IsDecoded, &encoded,
  71.                         IMG_ImagePlanar, &attrs[0],
  72.                         IMG_ImageChunky,&attrs[1],
  73.                         IMG_ImageHAM6, &attrs[2],
  74.                         IMG_ImageHalfBrite, &attrs[3],
  75.                         IMG_ImageHAM8, &attrs[4],
  76.                         IMG_Image24Bit, &attrs[5],
  77.                         IMG_ImagePalette, &attrs[6],
  78.                         IMG_ImageGrey, &attrs[7],
  79.                         IMG_ImageDepth, &depth,
  80.                         TAG_DONE );
  81.                     if ( !err )
  82.                     {
  83.                         printf( "width=%ld, height=%ld\n", x, y );
  84.                         printf( "bytes per pixel=%ld, colourspace=%d\n", bpp, cs );
  85.                         printf( "row size=%ld\n", rs );
  86.                         printf( "image is decoded %s\n", encoded == TRUE ? "yes" : "no" );
  87.  
  88.                         if ( attrs[0] ) printf( "planar, " );
  89.                         if ( attrs[1] ) printf( "chunky, " );
  90.                         if ( attrs[2] ) printf( "HAM6 " );
  91.                         if ( attrs[3] ) printf( "HALFBRITE " );
  92.                         if ( attrs[4] ) printf( "HAM8 " );
  93.                         if ( attrs[5] ) printf( "24bit " );
  94.                         if ( attrs[6] ) printf( "palette " );
  95.                         if ( attrs[7] ) printf( "grey" );
  96.                         printf( "\n" );
  97.  
  98.                         printf( "depth=%d\n", depth );
  99.                     }
  100.                     else printf( "get image attrs error:%d\n", err );
  101.  
  102.                     FreeImage( ih );
  103.                 }
  104.                 else printf( "alloc image error:%d\n", err );
  105.  
  106.                 Close( fp );
  107.             }
  108.             else printf( "cant open file\n" );
  109.         }
  110.  
  111.         if ( ImageIOBase ) CloseLibrary( ImageIOBase );
  112.         if ( IntuitionBase ) CloseLibrary ( IntuitionBase );
  113.     }
  114.     else printf( "no file specified\n" );
  115. }
  116.  
  117. __saveds __asm ULONG progressFunc( register __d0 ULONG curr, register __d1 ULONG lines, register __a0 void *userdata )
  118. {
  119.     static int prevpercent = 0;
  120.  
  121.     int percent = ( curr * 100 ) / lines;
  122.  
  123.     if ( prevpercent != percent )
  124.     {
  125.         if ( percent % 10 == 0 ) printf( "%d%%\n", percent );
  126.     }
  127.  
  128.     prevpercent = percent;
  129.  
  130.     return NULL;
  131. }
  132.